/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.web.attence;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.unis.common.ui.jqGrid.GridUIMapper;
import com.unis.common.util.WebUtil;
import com.unis.model.BaseModel;
import com.unis.model.attence.DutyMotion;
import com.unis.service.attence.DutyMotionService;

/**
 * @author Administrator (email:raulcsj@163.com)
 * @since 2013-01-31
 */
@Controller
@RequestMapping("/dutymotion")
public class DutyMotionController {

    private DutyMotionService dutymotionService;

    /****************************************
     * Insert a instace of DutyMotion
     ****************************************/
    @RequestMapping("/insert")
    @ResponseBody
    public Object insertDutyMotion(@RequestBody DutyMotion dutymotion) throws Exception {
        dutymotion.setStatmentId("DutyMotion.insert");
        String status = "failure";
        dutymotionService.insert(dutymotion);
        status = "success";
        return status;
    }

    /****************************************
     * Update a instace of DutyMotion
     ****************************************/
    @RequestMapping("/update")
    @ResponseBody
    public Object update(@RequestBody DutyMotion dutymotion) throws Exception {
        dutymotion.setStatmentId("DutyMotion.update");
        String status = "failure";
        dutymotionService.update(dutymotion);
        status = "success";
        return status;
    }

    /****************************************
     * Delete a instace of DutyMotion
     ****************************************/
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(@RequestBody DutyMotion dutymotion) throws Exception {
        dutymotion.setStatmentId("DutyMotion.delete");
        String status = "failure";
        dutymotionService.batchDelete(dutymotion);
        status = "success";
        return status;
    }

    /****************************************
     * Query instaces of DutyMotion
     ****************************************/
    @RequestMapping("/queryAsList")
    @ResponseBody
    public Object queryAsList(HttpServletRequest request) throws Exception {
        Map<String, Object> paramMap = WebUtil.getParamsMapFromRequest(request);
        DutyMotion dutymotion = new DutyMotion();
        dutymotion.setStatmentId("DutyMotion.queryAsList");
        BeanUtils.populate(dutymotion, paramMap);
        Map<String, Object> pageMap = GridUIMapper.process(paramMap);
        BeanUtils.populate(dutymotion, pageMap);
        List<BaseModel> dutymotionList = dutymotionService.queryAsList(dutymotion);
        Map<String, Object> renderMap = GridUIMapper.render(dutymotion, dutymotionList);
        return renderMap;
    }

    /****************************************
     * Query a instaces of DutyMotion
     ****************************************/
    @RequestMapping("/queryAsObject")
    @ResponseBody
    public BaseModel queryAsObject(@RequestBody DutyMotion dutymotion) throws Exception {
        dutymotion.setStatmentId("DutyMotion.queryAsObject");
        return dutymotionService.queryAsObject(dutymotion);
    }

    @RequestMapping("/page")
    public String forword() {
        return "attence/dutymotionList";
    }

    @Resource
    public void setDutyMotionService(DutyMotionService dutymotionService) {
        this.dutymotionService = dutymotionService;
    }
}
